package com.kmproject.haifu.mvp.ui.widget;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;

import java.util.List;

/**
 * Created by Administrator on 2017/3/13 0013.
 * E-Mail：543441727@qq.com
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private List<Subject> datas;
    private Context mContext;
    private LayoutInflater mLiLayoutInflater;
    ImageLoader glideImage;
    public MyAdapter(List<Subject> datas, Context context) {
        this.datas = datas;
        this.mContext = context;
        this.mLiLayoutInflater = LayoutInflater.from(mContext);
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
    }
    public void refershDataOne(Subject data)
    {
        if (data!=null)
        {
            this.datas.add(data);
            notifyDataSetChanged();
        }
    }
    public void refershData(List<Subject> datas)
    {
        if (datas!=null)
        {
            this.datas = datas;
        }else {
            this.datas.clear();
        }
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLiLayoutInflater.inflate(R.layout.item_linear, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

//        holder.img.setImageResource(datas.get(position).getImg());
        Glide.with(mContext)
                .load(datas.get(position).filepath)
                .into(holder.img);
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
//        TextView tv_title;
        ImageView img;
        LinearLayout ll_item;//, ll_hidden;
        ImageView delimg;
        public ViewHolder(View itemView) {
            super(itemView);
//            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
            img = (ImageView) itemView.findViewById(R.id.img);
            delimg = (ImageView) itemView.findViewById(R.id.item_del_img);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
//            ll_hidden = (LinearLayout) itemView.findViewById(R.id.ll_hidden);
        }
    }
}
